package com.sinoparasoft.caldeirao;

import org.openstack4j.model.identity.Tenant;
import org.openstack4j.model.network.IP;
import org.openstack4j.model.network.NetFloatingIP;
import org.openstack4j.model.network.Port;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
    	Cloud cloud = new Cloud();

/*    	for (NetFloatingIP ip: cloud.getFloatingIPs()) {
    		showFloatingIP(ip);
    	}*/
    	
//    	for (Port port: cloud.getPublicPorts()) {
//    		showPort(port);
//    	}
    	
//    	Tenant tenant = cloud.createTenant("demo2", "demo tenant 2");
//    	showTenant(tenant);
//    	
//		for (Tenant t: cloud.getTenants()) {
//			showTenant(t);
//		}
    	
//    	for (ExternalIp ip: cloud.getExternalIps()) {
//    		showExternalIp(ip);
//    	}
		cloud.addFloatingIpToServer();
		
    	System.out.println("########　finished ########");
    	
        return;
    }    

	private static void showExternalIp(ExternalIp ip) {
		System.out.println(
				ip.getAddress() + '\t' +
				ip.getStatus());		
	}

	private static void showFloatingIP(NetFloatingIP ip) {
		System.out.println(
				ip.getFloatingIpAddress() + '\t' +
				// ip.getFloatingNetworkId() + '\t' +
				// ip.getId() + '\t' +
				ip.getPortId() + '\t' +
				ip.getRouterId() + '\t' +
				ip.getTenantId() + '\t' + 
				ip.getFixedIpAddress());
		
		return;
	}
	
	private static void showPort(Port port) {
		System.out.print(
				port.getDeviceId() + '\t' +
				port.getDeviceOwner() + '\t' + 
				port.getId() + '\t' + 
				port.getMacAddress() + '\t' + 
				// port.getName() + '\t' + 
				port.getNetworkId() + '\t' + 
				// port.getTenantId() + '\t' + 
				port.getState() + '\t');
		
		for (IP ip: port.getFixedIps()) {
			System.out.print(ip.getIpAddress() + '\t');
		}
		
		System.out.println();
	}
	
	private static void showTenant(Tenant tenant) {
		System.out.println(
				tenant.getId() + '\t' + 
				tenant.getName() + '\t' +
				tenant.getDescription() + '\t' +
				tenant.isEnabled());
		
		return;
	}
}
